﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using XXN.Model.Model;
using XXN.Service;

namespace XXN.Admin.Controllers
{
    public class GuideController : Controller
    {
        GuideService gu = new GuideService();
        // GET: Guide
        public ActionResult Index()
        {
            return View();
        }
        public ActionResult GetGuide(int page, int limit, string productName)
        {
            var count = 0;
            var list = gu.GetGuide(page, limit, productName, out count);
            return Json(new { code = 0, msg = "", count = count, data = list }, JsonRequestBehavior.AllowGet);
        }
        [HttpGet]
        public ActionResult AddInfo()
        {
            return View();
        }
        [HttpPost]
        public ActionResult AddInfo(Guide guide)
        {
            var n = gu.AddInfo(guide);
            if (n > 0)
            {
                return Json(new { success = true, msg = "添加成功" });
            }
            return Json(new { success = false, msg = "添加失败" });
        }
        [HttpGet]
        public ActionResult EditInfo(int id)
        {
            var re = gu.EditInfo(id);
            var emptype = gu.GetGuideProductTypeInfo();
            List<SelectListItem> type = new List<SelectListItem>();
            foreach (var item in emptype)
            {
                type.Add(new SelectListItem() { Value = item.Pro_id.ToString(), Text = item.Pro_name });
            }
            ViewData["type"] = type;
            return View(re);
        }
        [HttpPost]
        public ActionResult EditInfo(Guide guide)
        {
            var n = gu.EditInfo(guide);
            if (n > 0)
            {
                return Json(new { success = true, msg = "编辑成功" });
            }
            return Json(new { success = false, msg = "编辑失败" });
        }
        public ActionResult DelInfo(int id)
        {
            int n = gu.DelInfo(id);
            return Content(n.ToString());
        }
    }
}